home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / e10_edit.arc / ECONFIG.PAS < prev    next >
Pascal/Delphi Source File  |  1990-03-22  |  7KB  |  282 lines

  1. {Configuration program for E.COM, (C) Jim DeVries, 1990.  A limited license is
  2. granted for anyone to use and share this program without charge, but you are
  3. prohibited from selling it or releasing a modified copy without prior written
  4. approval or releasing ECONFIG.EXE without this file}
  5.  
  6. Program EConfig;  uses CRT, Dos;
  7.  
  8. Const
  9.    ProgramLength = 6337;
  10.    ConfigStarts = $40; {offset from beginning of file}
  11.    {offsets}
  12.    cs = 0;  {Status line attributes  }
  13.    ct = 1;  {text attributes         }
  14.    tw = 2;  {tab width               }
  15.    io = 3;  {insert / overwrite flag }
  16.    ai = 4;  {Autoinsert flag         }
  17.    tm = 5;  {text / program mode flag}
  18.    lm = 6;  {right margin            }
  19.    rm = 7;  {left margin             }
  20.  
  21.    stop = 0;
  22.  
  23. TYPE
  24.   BufArray = array[0..ProgramLength-1] of byte;
  25.  
  26. VAR
  27.    Infile, Outfile : file;
  28.    Buffer : BufArray;
  29.    Cmd : integer;
  30. Function ColorWord(CNum : integer):String;
  31. begin
  32.    case CNum of
  33.    0: ColorWord:='black        ';
  34.    1: ColorWord:='blue         ';
  35.    2: ColorWord:='green        ';
  36.    3: ColorWord:='cyan         ';
  37.    4: ColorWord:='red          ';
  38.    5: ColorWord:='magenta      ';
  39.    6: ColorWord:='brown        ';
  40.    7: ColorWord:='white        ';
  41.    8: ColorWord:='dark grey    ';
  42.    9: ColorWord:='light blue   ';
  43.   10: ColorWord:='light green  ';
  44.   11: ColorWord:='light cyan   ';
  45.   12: ColorWord:='light red    ';
  46.   13: ColorWord:='light magenta';
  47.   14: ColorWord:='yellow       ';
  48.   15: ColorWord:='bright white ';
  49.   end; {case}
  50. end;
  51.  
  52. Procedure PickColor(OffSet : Integer; VAR Buffer : BufArray);
  53. var x,y,fore, back : integer;
  54. begin
  55.    back:=Buffer[ConfigStarts+OffSet] shr 4;
  56.    fore:=Buffer[ConfigStarts+OffSet] and 15;
  57.    textcolor(fore);
  58.    textbackground(back);
  59.    for x:=0 to 3 do
  60.       for y:=0 to 3 do
  61.       begin
  62.          gotoxy(x*15+1,y+21);
  63.          write(x*4+y:2,' ',colorword(x*4+y));
  64.          end;
  65.    textcolor(yellow);
  66.    textbackground(blue);
  67.    gotoxy(1,20);
  68.    clreol;
  69.    repeat
  70.       gotoxy(1,19);
  71.       write('Enter a new foreground color ');
  72.       read(fore);
  73.       until fore IN [0..15];
  74.    repeat
  75.       gotoxy(33,19);
  76.       write(' Enter a new background color (0..7) ');
  77.       read(back);
  78.       until back in [0..7];
  79.    Buffer[ConfigStarts+Offset]:=back*16+fore;
  80.    for y:=19 to 24 do
  81.    begin
  82.       gotoxy(1,y);
  83.       clreol;
  84.       end;
  85. end;
  86.  
  87. Procedure SetTab(VAR Buffer : BufArray);
  88. var Tab : byte;
  89. begin
  90.    gotoxy(1,20);
  91.    clreol;
  92.    gotoxy(1,22);
  93.    write('Enter tab width ');
  94.    readln(tab);
  95.    Buffer[ConfigStarts+TW]:=tab;
  96.    gotoxy(1,22);
  97.    clreol;
  98. end;
  99.  
  100. Procedure SetMargins(VAR Buffer : BufArray);
  101. var left, right : byte;
  102. begin
  103.    gotoxy(1,20);
  104.    clreol;
  105.    gotoxy(1,22);
  106.    write  ('...............................................',
  107.            '.................................');
  108.    left:=Buffer[ConfigStarts+LM];
  109.    right:=Buffer[ConfigStarts+RM];
  110.    gotoxy(left,22);
  111.    write(chr(16));
  112.    gotoxy(right,22);
  113.    write(chr(17));
  114.    repeat
  115.       repeat
  116.          gotoxy(1,23);
  117.          write('Enter new left margin ');
  118.          read(left);
  119.          until left in [1..79];
  120.       repeat
  121.          gotoxy(1,24);
  122.          write('Enter new right margin ');
  123.          read(right);
  124.          until right in [1..80];
  125.       if right <= Left then
  126.          begin
  127.             gotoxy(1,25);
  128.             write('The LEFT margin must be to the left of the RIGHT one!!!');
  129.             end;
  130.       until right > left;
  131.    Buffer[ConfigStarts+LM]:=left;
  132.    Buffer[ConfigStarts+RM]:=right;
  133.    for left:=22 to 25 do
  134.    begin
  135.       gotoxy(1,left);
  136.       clreol;
  137.       end;
  138.  
  139. end;
  140.  
  141. Procedure OpenFile(VAR Infile:File);
  142. begin
  143.    Assign(infile,'E.COM');
  144.    reset(infile,1);
  145.    BlockRead(infile, buffer, ProgramLength);
  146.    close(infile);
  147. end;
  148.  
  149. Procedure PrintHeading;
  150. begin
  151.    clrscr;
  152.    gotoxy(1,3);
  153.    writeln('                         E   C O N F I G U R A T I O N');
  154.    writeln;
  155.    writeln('     E.COM               (C) Copyright 1990, David Nye, MD.');
  156.    writeln('     ECONFIG.EXE         (C) Copyright 1990, Jim DeVries');
  157.    writeln;
  158.    write  ('-----------------------------------------------',
  159.            '---------------------------------');
  160.    gotoxy(1,9);
  161.    writeln('                                              Currently:');
  162.    writeln('     1.  Status line colors.................');
  163.    writeln('     2.  Text colors........................');
  164.    writeln('     3.  Tab width..........................');
  165.    writeln('     4.  Toggle Insert / Overwrite mode.....');
  166.    writeln('     5.  Toggle AutoInsert..................');
  167.    writeln('     6.  Toggle Program / Text mode.........');
  168.    writeln('     7.  Change Margins for text mode.......');
  169. end;
  170.  
  171. Procedure ShowCurrent(VAR Buffer : BufArray);
  172. var r,l, temp, back, fore : byte;
  173. begin
  174.    back:=Buffer[ConfigStarts+CS] shr 4;
  175.    fore:=Buffer[ConfigStarts+Cs] and 15;
  176.    gotoxy(47,10);
  177.    write(ColorWord(fore),' ON ', ColorWord(back));
  178.    clreol;
  179.    back:=Buffer[ConfigStarts+CT] shr 4;
  180.    fore:=Buffer[ConfigStarts+CT] and 15;
  181.    gotoxy(47,11);
  182.    write(ColorWord(fore),' ON ', ColorWord(back));
  183.    clreol;
  184.    temp:=Buffer[ConfigStarts+TW];
  185.    gotoxy(47,12);
  186.    write(Temp);
  187.    temp:=Buffer[ConfigStarts+IO];
  188.    gotoxy(47,13);
  189.    if temp=$FF then Write('INSERT   ')
  190.       else write('OVERWRITE');
  191.    gotoxy(47,14);
  192.    temp:=Buffer[ConfigStarts+AI];
  193.    If temp=$FF then write('ON ')
  194.       else write('OFF');
  195.    gotoxy(47,15);
  196.    temp:=Buffer[ConfigStarts+TM];
  197.    If temp=$FF then write('TEXT MODE   ')
  198.       else write('PROGRAM MODE');
  199.    l:=Buffer[ConfigStarts+LM];
  200.    r:=Buffer[ConfigStarts+RM];
  201.    gotoxy(47,16);
  202.    write(l, ' L & ',r,' R');
  203.    gotoxy(1,20);
  204.    write('     Change (1..7)  Esc to quit');
  205.  
  206. end;
  207.  
  208. Procedure GetCommand(VAR Cmd : integer);
  209. var c: char;
  210. begin
  211.    repeat
  212.       c:=readkey;
  213.    until C in ['1'..'7',#27];
  214.    If C=#27 then Cmd:=Stop
  215.       else Cmd:=Ord(C)-Ord('0');
  216. end;
  217.  
  218. procedure ProcessCmd(Cmd : Integer; VAR Buffer : BufArray);
  219. begin
  220.    Case Cmd of
  221.    Stop : Exit;
  222.    1: PickColor(CS, Buffer);
  223.    2: PickColor(CT, Buffer);
  224.    3: SetTab(Buffer);
  225.    4: Buffer[ConfigStarts+IO]:= Buffer[ConfigStarts+IO] XOR $FF;
  226.    5: Buffer[ConfigStarts+AI]:= Buffer[ConfigStarts+AI] XOR $FF;
  227.    6: Buffer[ConfigStarts+TM]:= Buffer[ConfigStarts+TM] XOR $FF;
  228.    7: SetMargins(Buffer);
  229.    end;
  230.  
  231. end;
  232.  
  233. Procedure CloseFile(VAR Buffer : BufArray);
  234. var yn : char;
  235.     fn : string;
  236.     outfile : file;
  237. begin
  238.    gotoxy(1,20);
  239.    clreol;
  240.    write('     Save changes? [Y/N] ');
  241.    repeat
  242.       yn:=readkey;
  243.    until upcase(yn) IN ['Y','N'];
  244.    writeln;
  245.    if upcase(yn) = 'N'
  246.       then exit
  247.    else
  248.    begin
  249.       write('    Save to E.COM? [Y/N] ');
  250.       Repeat
  251.          yn:=readkey;
  252.       until upcase(yn) in ['Y','N'];
  253.       if upcase(YN) = 'N' then
  254.       begin
  255.          writeln;
  256.          write('     Enter new file name: ');
  257.          read(fn);
  258.          end
  259.       else
  260.          fn:='E.COM';
  261.       end;
  262.    assign(outfile,fn);
  263.    if fn = 'E.COM' then
  264.       reset(outfile, 1)
  265.    else
  266.       rewrite(outfile);
  267.  
  268.    blockwrite(outfile, Buffer, ProgramLength);
  269.  
  270.    close(outfile);
  271. end;
  272.  
  273. begin
  274.    OpenFile(Infile);
  275.    PrintHeading;
  276.    repeat
  277.       ShowCurrent(buffer);
  278.       GetCommand(Cmd);
  279.       ProcessCmd(Cmd,Buffer);
  280.       until Cmd = Stop;
  281.    closefile(buffer);
  282. end.